package com.handpay.nocardpay.baselibrary.pay.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.pay.unipay.model.bean.HistoryBankCardListBean;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;

import java.util.List;

/**
 * Created by lyang on 2017/8/16.
 */

public class NoCardPayListCardNoAdapter extends BaseAdapter {

    private List<HistoryBankCardListBean.ListBean> mBankCardInfoList;
    private Context mContext;

    public NoCardPayListCardNoAdapter(Context context) {
        mContext = context;
    }

    @Override
    public int getCount() {
        if (mBankCardInfoList != null) {
            return mBankCardInfoList.size() + 1;
        }
        return 0;
    }

    @Override
    public HistoryBankCardListBean.ListBean getItem(int position) {
        return mBankCardInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        BankCardItem bankCardItem = new BankCardItem();
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_no_card_pay_card_no_list_item, null);
            bankCardItem.bank_name_tv = (TextView) convertView.findViewById(R.id.bank_name_tv);
            bankCardItem.bank_card_no_tv = (TextView) convertView.findViewById(R.id.bank_card_no_tv);
            convertView.setTag(bankCardItem);
        } else {
            bankCardItem = (BankCardItem) convertView.getTag();
        }
        if (position == (this.getCount() - 1)) {
            if (this.getCount()==1){
                bankCardItem.bank_name_tv.setText("无历史卡记录");
                bankCardItem.bank_card_no_tv.setVisibility(View.INVISIBLE);
            }else{
                bankCardItem.bank_name_tv.setText("清除历史卡");
                bankCardItem.bank_card_no_tv.setVisibility(View.INVISIBLE);
            }

        } else {
            bankCardItem.bank_card_no_tv.setVisibility(View.VISIBLE);
            bankCardItem.bank_name_tv.setText(getItem(position).getBankName());
            bankCardItem.bank_card_no_tv.setText(CommonUtils.formattingCard(getItem(position).getCardNo()));
        }
        return convertView;
    }

    public void setData(List<HistoryBankCardListBean.ListBean> bankCardInfoList) {
        mBankCardInfoList = bankCardInfoList;
    }

    class BankCardItem {
        public TextView bank_name_tv = null;
        public TextView bank_card_no_tv = null;

    }
}